package org.bagou.xiangs.framework_mvvm.older

import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import androidx.databinding.DataBindingUtil
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.alibaba.android.arouter.facade.annotation.Route
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.MainScope
import kotlinx.coroutines.launch
import org.bagou.xiangs.framework_mvvm.R
import org.bagou.xiangs.framework_mvvm.databinding.ActivityOldDatabindingmvvmBinding


@Route(path = "/old/activity/OldMvvmActivity")
class DataBindingOldMvvmActivity : AppCompatActivity() {
    private lateinit var binding: ActivityOldDatabindingmvvmBinding
    private lateinit var viewModelMvvm: DataBindingOldViewModelMvvm

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        binding = DataBindingUtil.setContentView(this, R.layout.activity_old_databindingmvvm)
        viewModelMvvm = DataBindingOldViewModelMvvm()
        binding!!.oldMvvm = viewModelMvvm
        MainScope().launch(Dispatchers.IO) {
        }
        viewModelMvvm!!.getUserInfoPromote(this, DataBindingOldViewModelMvvm.ViewModelCallback {
            onUpdateUI(it)
        })

    }


    private fun onUpdateUI(wechatInfo: WechatInfo) {

        val layoutManager = LinearLayoutManager(this)
        layoutManager.orientation = RecyclerView.VERTICAL
        binding!!.recycleList.layoutManager = layoutManager
        val adapter = DataBindingOldAdapter()
        binding!!.recycleList.adapter = adapter
        adapter.addData(wechatInfo.list)
    }


}
